<?php

namespace App\Admin\Controllers;

use App\Models\Faq;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class FaqController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('客服中心');
            $content->description('客服中心');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('客服中心');
            $content->description('客服中心');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('客服中心');
            $content->description('客服中心');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(Faq::class, function (Grid $grid) {
            $grid->id('ID')->sortable();
            $grid->title('标题');
            $grid->desc('描述');
            $grid->content('内容');
            $grid->is_show('是否显示')->display(function ($data){
                return $data?'是':'否';
            });
            $grid->sort('排序')->sortable();
            $grid->created_at('创建时间');
            $grid->updated_at('更新时间');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(Faq::class, function (Form $form) {
            $form->text('title','标题（7字以内）');
            $form->text('desc','描述（7字以内）');
            $form->text('content','内容（200字以内）');
            $form->number('sort','排序');
            $form->radio('is_show','是否显示')->options(['0' => '否', '1'=> '是'])->default('1');
        });
    }
}
